home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OT PAPServerSample / EnableSelfSendSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.2 KB  |  119 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        EnableSelfSendSample.c
  3.  
  4.     Contains:    Demonstrate the use of the OTOptionManagement call to tell an AppleTalk
  5.                 endpoint to enable/disable the SelfSend option.
  6.  
  7.     Written by: Rich Kubota    
  8.  
  9.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/22/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 1/25/98        rrk             Changed the original use of the OTOptionManagement
  22.                                              call, OPT_SELFSEND which only enables selfsend from
  23.                                              the endpoint to other AppleTalk services when broadcast
  24.                                              messages are sent from the endpoint.  The desired behavior
  25.                                              is one where if other AppleTalk clients on the node send
  26.                                              broadcast messages, that they are also sent to the endpoint.
  27.                                              To this end, there is the ATALK_IOC_FULLSELFSEND Ioct, which
  28.                                              must be sent to the DDP endpoint.
  29.                 
  30.                                             Note that the ATALK_IOC_FULLSELFSEND is desired to respond
  31.                                             similarly to the PSetSelfSend function.  If the result is
  32.                                             not negative, then the following responses can be expected.
  33.                 
  34.                                             0 - FullSelfSend was previously off
  35.                                             1 - FullSelfSend was previously on
  36.                 
  37.                                             Input parameters
  38.                 
  39.                                             ep - the AppleTalk EndpointRef on which to enable
  40.                                             fullSelfSend. You can pass any AppleTalk endpoint,
  41.                                             DDP or above, to this function. 
  42.                                             enableSelfSend - a long word of the desired setting.
  43.                 
  44.                                             Return result
  45.                                             < 0 - error
  46.                                             0 - FullSelfSend was previously off
  47.                                             1 - FullSelfSend was previously on
  48.                 
  49.                                             Note that if the use of the Ioctl returns an error < 0, then
  50.                                             the PBSetSelfSend function is called.
  51.                 
  52.                                             Note: As with the PSetSelfSend call, the Ioctl call affects
  53.                                             AppleTalk globally. If you enable this feature, it is
  54.                                             recommended that you not disable the feature when the 
  55.                                             process quits.  The user may launch another process which
  56.                                             enables selfsend.  Turning off selfsend in this case,
  57.                                             affects the other process, as well.
  58.                 
  59.  
  60. */
  61.  
  62. #include "OpenTransport.h"            // open transport files            
  63. #include "OpenTptAppletalk.h"
  64. #include "AppleTalk.h"
  65.  
  66. extern OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend);
  67.  
  68.  
  69. /*
  70.     Sample function to enable/disable the SelfSend option for 
  71.     an AppleTalk endpoint. 
  72.  
  73.     Input
  74.     EndpointRef ep - endpoint on which to set SelfSend option on
  75.     long enableSelfSend - 1L - option on, 0L - option off
  76.  
  77.    Return: kOTNoError indicates that the option was successfully negotiated
  78.                otherwise the error result is returned
  79.  
  80.     IMPORTANT NOTE: if you find that this sample fails to enable/disable self send, check
  81.             the file OpenTptAppleTalk.h and ensure that ATALK_IOC_FULLSELFSEND is defined 
  82.             as follows
  83.             
  84.         #define ATALK_IOC_FULLSELFSEND            MIOC_CMD(MIOC_ATALK,47)
  85.         
  86.             there are versions of the header file that incorrectly define 
  87.             ATALK_IOC_FULLSELFSEND as follows.
  88.             
  89.         #define ATALK_IOC_FULLSELFSEND            MIOC_CMD(MIOC_ATALK,47) // INCORRECT
  90.             
  91.  
  92.     
  93. */
  94. OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend)
  95.  
  96. {
  97.     OSStatus        result;
  98.     SetSelfparms    pb;
  99.     Boolean            usePB = false;
  100.     
  101.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  102.         usePB = true;
  103.     else
  104.     {
  105.         result = OTIoctl(ep, ATALK_IOC_FULLSELFSEND, (void*)enableSelfSend);
  106.         if (result < kOTNoError)
  107.             usePB = true;    // if an error occured, try using the PBSetSelfSend call
  108.     }
  109.     
  110.     if (usePB == true)
  111.     {
  112.         pb.newSelfFlag = enableSelfSend != 0 ? true : false;  /* set self send option */
  113.         result = PSetSelfSend((MPPPBPtr) &pb, false);
  114.         
  115.     }
  116.         
  117.     return result;
  118. }
  119.